
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="Python">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>deepaugment.deepaugment &#8212; deepaugment 0.2.0 documentation</title>
    <link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for deepaugment.deepaugment</h1><div class="highlight"><pre>
<span></span><span class="c1"># (C) 2019 Baris Ozmen &lt;hbaristr@gmail.com&gt;</span>

<span class="kn">import</span> <span class="nn">tensorflow</span> <span class="k">as</span> <span class="nn">tf</span>
<span class="kn">import</span> <span class="nn">keras</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">ConfigProto</span><span class="p">()</span>
<span class="n">config</span><span class="o">.</span><span class="n">gpu_options</span><span class="o">.</span><span class="n">allow_growth</span> <span class="o">=</span> <span class="kc">True</span>  <span class="c1"># tell tensorflow not to use all resources</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">tf</span><span class="o">.</span><span class="n">Session</span><span class="p">(</span><span class="n">config</span><span class="o">=</span><span class="n">config</span><span class="p">)</span>
<span class="n">keras</span><span class="o">.</span><span class="n">backend</span><span class="o">.</span><span class="n">set_session</span><span class="p">(</span><span class="n">session</span><span class="p">)</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="k">import</span> <span class="n">dirname</span><span class="p">,</span> <span class="n">realpath</span>
<span class="kn">import</span> <span class="nn">pathlib</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">click</span>

<span class="n">file_path</span> <span class="o">=</span> <span class="n">realpath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
<span class="n">dir_of_file</span> <span class="o">=</span> <span class="n">dirname</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
<span class="n">parent_dir_of_file</span> <span class="o">=</span> <span class="n">dirname</span><span class="p">(</span><span class="n">dir_of_file</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">parent_dir_of_file</span><span class="p">)</span>
<span class="c1"># Set experiment name</span>
<span class="kn">import</span> <span class="nn">datetime</span>
<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
<span class="n">EXPERIMENT_NAME</span> <span class="o">=</span> <span class="p">(</span>
    <span class="n">f</span><span class="s2">&quot;</span><span class="si">{now.month:02}</span><span class="s2">-</span><span class="si">{now.day:02}</span><span class="s2">_</span><span class="si">{now.hour:02}</span><span class="s2">-</span><span class="si">{now.minute:02}</span><span class="s2">&quot;</span>
<span class="p">)</span>
<span class="n">EXPERIMENT_FOLDER_PATH</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
    <span class="n">parent_dir_of_file</span><span class="p">,</span> <span class="n">f</span><span class="s2">&quot;reports/experiments/</span><span class="si">{EXPERIMENT_NAME}</span><span class="s2">&quot;</span>
<span class="p">)</span>
<span class="n">log_path</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">EXPERIMENT_FOLDER_PATH</span><span class="p">)</span>
<span class="n">log_path</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">parents</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="c1"># import modules from DeepAugmenter</span>
<span class="kn">from</span> <span class="nn">deepaugment.controller</span> <span class="k">import</span> <span class="n">Controller</span>
<span class="kn">from</span> <span class="nn">deepaugment.objective</span> <span class="k">import</span> <span class="n">Objective</span>
<span class="kn">from</span> <span class="nn">deepaugment.childcnn</span> <span class="k">import</span> <span class="n">ChildCNN</span>
<span class="kn">from</span> <span class="nn">deepaugment.notebook</span> <span class="k">import</span> <span class="n">Notebook</span>
<span class="kn">from</span> <span class="nn">deepaugment.build_features</span> <span class="k">import</span> <span class="n">DataOp</span>
<span class="kn">from</span> <span class="nn">deepaugment.lib.decorators</span> <span class="k">import</span> <span class="n">Reporter</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">Reporter</span><span class="o">.</span><span class="n">logger</span>


<span class="c1"># warn user if TensorFlow does not see the GPU</span>
<span class="kn">from</span> <span class="nn">tensorflow.python.client</span> <span class="k">import</span> <span class="n">device_lib</span>
<span class="k">if</span> <span class="s2">&quot;GPU&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="nb">str</span><span class="p">(</span><span class="n">device_lib</span><span class="o">.</span><span class="n">list_local_devices</span><span class="p">()):</span>
    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;GPU not available!&quot;</span><span class="p">)</span>
    <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;GPU not available!&quot;</span><span class="p">)</span>
<span class="c1"># Note: GPU not among local devices means GPU not used for sure,</span>
<span class="c1">#       HOWEVER GPU among local devices does not guarantee it is used</span>


<span class="n">DEFAULT_CONFIG</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;model&quot;</span><span class="p">:</span> <span class="s2">&quot;basiccnn&quot;</span><span class="p">,</span>
    <span class="s2">&quot;method&quot;</span><span class="p">:</span> <span class="s2">&quot;bayesian_optimization&quot;</span><span class="p">,</span>
    <span class="s2">&quot;train_set_size&quot;</span><span class="p">:</span> <span class="mi">2000</span><span class="p">,</span>
    <span class="s2">&quot;opt_samples&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
    <span class="s2">&quot;opt_last_n_epochs&quot;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
    <span class="s2">&quot;opt_initial_points&quot;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span>
    <span class="s2">&quot;child_epochs&quot;</span><span class="p">:</span> <span class="mi">50</span><span class="p">,</span>
    <span class="s2">&quot;child_first_train_epochs&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
    <span class="s2">&quot;child_batch_size&quot;</span><span class="p">:</span> <span class="mi">64</span><span class="p">,</span>
    <span class="s2">&quot;pre_aug_weights_path&quot;</span><span class="p">:</span> <span class="s2">&quot;pre_aug_weights.h5&quot;</span><span class="p">,</span>
    <span class="s2">&quot;logging&quot;</span><span class="p">:</span> <span class="n">logging</span><span class="p">,</span>
    <span class="s2">&quot;notebook_path&quot;</span><span class="p">:</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{EXPERIMENT_FOLDER_PATH}</span><span class="s2">/notebook.csv&quot;</span>
<span class="p">}</span>


<div class="viewcode-block" id="DeepAugment"><a class="viewcode-back" href="../../deepaugment.deepaugment.html#deepaugment.deepaugment.DeepAugment">[docs]</a><span class="k">class</span> <span class="nc">DeepAugment</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Initiliazes commponents of DeepAugment (e.g. Controller, Child-model, Notebook) and optimizes image augmentation hyperparameters</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@logger</span><span class="p">(</span><span class="n">logfile_dir</span><span class="o">=</span><span class="n">EXPERIMENT_FOLDER_PATH</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">images</span><span class="o">=</span><span class="s2">&quot;cifar10&quot;</span><span class="p">,</span>
        <span class="n">labels</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
        <span class="n">config</span><span class="o">=</span><span class="p">{}</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initializes DeepAugment object</span>

<span class="sd">        Does following steps:</span>
<span class="sd">            1. load and preprocess data</span>
<span class="sd">            2. create child model</span>
<span class="sd">            3. create controller</span>
<span class="sd">            4. create notebook (for recording trainings)</span>
<span class="sd">            5. do initial training</span>
<span class="sd">            6. create objective function</span>
<span class="sd">            7. evaluate objective function without augmentation</span>

<span class="sd">        Args:</span>
<span class="sd">            images (numpy.array/str): array with shape (n_images, dim1, dim2 , channel_size), or a string with name of keras-dataset (cifar10, fashion_mnsit)</span>
<span class="sd">            labels (numpy.array): labels of images, array with shape (n_images) where each element is an integer from 0 to number of classes</span>
<span class="sd">            config (dict): dictionary of configurations, for updating the default config which is:</span>
<span class="sd">                {</span>
<span class="sd">                    &quot;model&quot;: &quot;basiccnn&quot;,</span>
<span class="sd">                    &quot;method&quot;: &quot;bayesian_optimization&quot;,</span>
<span class="sd">                    &quot;train_set_size&quot;: 2000,</span>
<span class="sd">                    &quot;opt_samples&quot;: 3,</span>
<span class="sd">                    &quot;opt_last_n_epochs&quot;: 3,</span>
<span class="sd">                    &quot;opt_initial_points&quot;: 10,</span>
<span class="sd">                    &quot;child_epochs&quot;: 50,</span>
<span class="sd">                    &quot;child_first_train_epochs&quot;: 0,</span>
<span class="sd">                    &quot;child_batch_size&quot;: 64,</span>
<span class="sd">                    &quot;pre_aug_weights_path&quot;: &quot;pre_aug_weights.h5&quot;,</span>
<span class="sd">                    &quot;logging&quot;: logging,</span>
<span class="sd">                    &quot;notebook_path&quot;: f&quot;{EXPERIMENT_FOLDER_PATH}/notebook.csv&quot;</span>
<span class="sd">                }</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">=</span><span class="n">DEFAULT_CONFIG</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">iterated</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># keep tracks how many times optimizer iterated</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">load_and_preprocess_data</span><span class="p">(</span><span class="n">images</span><span class="p">,</span> <span class="n">labels</span><span class="p">)</span>

        <span class="c1"># define main objects</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">child_model</span> <span class="o">=</span> <span class="n">ChildCNN</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">input_shape</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_classes</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">controller</span> <span class="o">=</span> <span class="n">Controller</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">notebook</span> <span class="o">=</span> <span class="n">Notebook</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;child_first_train_epochs&quot;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">do_initial_training</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">child_model</span><span class="o">.</span><span class="n">save_pre_aug_weights</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">objective_func</span> <span class="o">=</span> <span class="n">Objective</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">child_model</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">notebook</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">evaluate_objective_func_without_augmentation</span><span class="p">()</span>

<div class="viewcode-block" id="DeepAugment.optimize"><a class="viewcode-back" href="../../deepaugment.deepaugment.html#deepaugment.deepaugment.DeepAugment.optimize">[docs]</a>    <span class="k">def</span> <span class="nf">optimize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterations</span> <span class="o">=</span> <span class="mi">300</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Optimize objective function hyperparameters using controller and child model</span>

<span class="sd">        Args:</span>
<span class="sd">            iterations (int): number of optimization iterations, which the child model will be run</span>

<span class="sd">        Returns:</span>
<span class="sd">            pandas.DataFrame: top policies (with highest expected accuracy increase)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># iteratate optimizer</span>
        <span class="k">for</span> <span class="n">trial_no</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">iterated</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">iterated</span> <span class="o">+</span> <span class="n">iterations</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
            <span class="n">trial_hyperparams</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">controller</span><span class="o">.</span><span class="n">ask</span><span class="p">()</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;trial:&quot;</span><span class="p">,</span> <span class="n">trial_no</span><span class="p">,</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">trial_hyperparams</span><span class="p">)</span>
            <span class="n">f_val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective_func</span><span class="o">.</span><span class="n">evaluate</span><span class="p">(</span><span class="n">trial_no</span><span class="p">,</span> <span class="n">trial_hyperparams</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">controller</span><span class="o">.</span><span class="n">tell</span><span class="p">(</span><span class="n">trial_hyperparams</span><span class="p">,</span> <span class="n">f_val</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">iterated</span><span class="o">+=</span><span class="n">iterations</span> <span class="c1"># update number of previous iterations</span>

        <span class="n">top_policies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">notebook</span><span class="o">.</span><span class="n">get_top_policies</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">notebook</span><span class="o">.</span><span class="n">output_top_policies</span><span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">top policies are:</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">top_policies</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">top_policies</span></div>

<div class="viewcode-block" id="DeepAugment.load_and_preprocess_data"><a class="viewcode-back" href="../../deepaugment.deepaugment.html#deepaugment.deepaugment.DeepAugment.load_and_preprocess_data">[docs]</a>    <span class="k">def</span> <span class="nf">load_and_preprocess_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">images</span><span class="p">,</span> <span class="n">labels</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Loads and preprocesses data</span>

<span class="sd">        Records `input_shape`, `data`, and `num_classes` into `self</span>

<span class="sd">        Args:</span>
<span class="sd">            images (numpy.array/str): array with shape (n_images, dim1, dim2 , channel_size), or a string with name of keras-dataset (cifar10, fashion_mnsit)</span>
<span class="sd">            labels (numpy.array): labels of images, array with shape (n_images) where each element is an integer from 0 to number of classes</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">images</span><span class="p">)</span> <span class="o">==</span> <span class="nb">str</span><span class="p">:</span>
            <span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_shape</span> <span class="o">=</span> <span class="n">DataOp</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">images</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">images</span><span class="p">,</span> <span class="n">labels</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input_shape</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">DataOp</span><span class="o">.</span><span class="n">preprocess</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;train_set_size&quot;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">num_classes</span> <span class="o">=</span> <span class="n">DataOp</span><span class="o">.</span><span class="n">find_num_classes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span></div>


<div class="viewcode-block" id="DeepAugment.do_initial_training"><a class="viewcode-back" href="../../deepaugment.deepaugment.html#deepaugment.deepaugment.DeepAugment.do_initial_training">[docs]</a>    <span class="k">def</span> <span class="nf">do_initial_training</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Do the first training without augmentations</span>

<span class="sd">        Training weights will be used as based to further child model trainings</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">history</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">child_model</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">epochs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;child_first_train_epochs&quot;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">notebook</span><span class="o">.</span><span class="n">record</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;first&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s2">&quot;first&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s2">&quot;first&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span> <span class="mi">1</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="n">history</span><span class="p">)</span></div>

<div class="viewcode-block" id="DeepAugment.evaluate_objective_func_without_augmentation"><a class="viewcode-back" href="../../deepaugment.deepaugment.html#deepaugment.deepaugment.DeepAugment.evaluate_objective_func_without_augmentation">[docs]</a>    <span class="k">def</span> <span class="nf">evaluate_objective_func_without_augmentation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Find out what would be the accuracy if augmentation are not applied</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">no_aug_hyperparams</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;crop&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="s2">&quot;crop&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">]</span>
        <span class="n">f_val</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">objective_func</span><span class="o">.</span><span class="n">evaluate</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">no_aug_hyperparams</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">controller</span><span class="o">.</span><span class="n">tell</span><span class="p">(</span><span class="n">no_aug_hyperparams</span><span class="p">,</span> <span class="n">f_val</span><span class="p">)</span></div></div>



<span class="nd">@click</span><span class="o">.</span><span class="n">command</span><span class="p">()</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--images&quot;</span><span class="p">,</span>  <span class="n">default</span><span class="o">=</span><span class="s2">&quot;cifar10&quot;</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--labels&quot;</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--model&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">STRING</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;basiccnn&quot;</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--method&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">STRING</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;bayesian_optimization&quot;</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--train-set-size&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">4000</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--opt-iterations&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--opt-samples&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--opt-last-n-epochs&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--opt-initial-points&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--child-epochs&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">15</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--child-first-train-epochs&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--child-batch-size&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">click</span><span class="o">.</span><span class="n">INT</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">main</span><span class="p">(</span>
    <span class="n">images</span><span class="p">,</span>
    <span class="n">labels</span><span class="p">,</span>
    <span class="n">model</span><span class="p">,</span>
    <span class="n">method</span><span class="p">,</span>
    <span class="n">train_set_size</span><span class="p">,</span>
    <span class="n">opt_iterations</span><span class="p">,</span>
    <span class="n">opt_samples</span><span class="p">,</span>
    <span class="n">opt_last_n_epochs</span><span class="p">,</span>
    <span class="n">opt_initial_points</span><span class="p">,</span>
    <span class="n">child_epochs</span><span class="p">,</span>
    <span class="n">child_first_train_epochs</span><span class="p">,</span>
    <span class="n">child_batch_size</span><span class="p">,</span>
<span class="p">):</span>
    <span class="n">DeepAugment</span><span class="p">(</span><span class="n">images</span><span class="p">,</span> <span class="n">labels</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="n">method</span><span class="p">,</span> <span class="n">train_set_size</span><span class="p">,</span> <span class="n">opt_iterations</span><span class="p">,</span> <span class="n">opt_samples</span><span class="p">,</span>
                <span class="n">opt_last_n_epochs</span><span class="p">,</span> <span class="n">opt_initial_points</span><span class="p">,</span> <span class="n">child_epochs</span><span class="p">,</span> <span class="n">child_first_train_epochs</span><span class="p">,</span>
                <span class="n">child_batch_size</span><span class="p">)</span>


<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
    <span class="n">main</span><span class="p">()</span>
</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../../index.html">deepaugment</a></h1>








<h3>Navigation</h3>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../index.html">Documentation overview</a><ul>
  <li><a href="../index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2019, Baris Ozmen.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.8.3</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>